<?php
namespace JsonRpc\Services\Product;
use JsonRpc\Models\PLabel;
use JsonRpc\Models\SysUser;
use JsonRpc\Services\CommonService;
use JsonRpc\Services\System\UserService;
use JsonRpc\Utils\Utils;

/**
 *  用户
 * @author walkor <worker-man@qq.com>
 */
class LabelService
{
    use CommonService;

    private static function getBaseModel(){
        return "JsonRpc\\Models\\PLabel";
    }

    public static function ping(){
        return 'OK';
    }

    public static function saveData($params){
        if(isset($params['id']) && $params['id']){
            //更新
            $model = PLabel::find($params['id']);
            $model->updated_by = $params['curr_user_id'];
        }else{
            $user = UserService::getInfoById(['id'=>$params['curr_user_id']]);
            //新增
            unset($params['id']);
            $model = new PLabel();
            $model->client_id = $user['client_id'];
            $model->org_id = $user['org_id'];
            $model->created_by = $user['id'];
            $model->updated_by = $user['id'];
        }
        $model->name = $params['name'];
        $model->is_recommend = $params['is_recommend'];
        return $model->save();
    }


}
